package com.huifaapp.mall.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.CacheUtils;
import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.huifaapp.mall.R;
import com.huifaapp.mall.afinal.SPConstants;
import com.huifaapp.mall.base.activity.BaseTitleBarActivity;
import com.huifaapp.mall.base.basemvp.IPresenter;
import com.huifaapp.mall.dialogs.CommonTowBtnDialog;
import com.huifaapp.mall.dialogs.LoadingDialog;
import com.huifaapp.mall.uitils.AppManager;
import com.huifaapp.mall.uitils.JPushUitil;
import com.huifaapp.mall.view.ClickTextView;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * author: wangZ
 * date：2017/9/1 15:33
 * FileName：SettingActivity
 * description：设置页面
 */

public class SettingActivity extends BaseTitleBarActivity {
    @BindView(R.id.rl_version)
    RelativeLayout rlVersion;
    @BindView(R.id.rl_cache)
    RelativeLayout rlCache;
    @BindView(R.id.ct_logOut)
    ClickTextView ctLogOut;
    @BindView(R.id.tv_versionCode)
    TextView tvVersionCode;

//    @Override
//    protected int getLayoutId() {
//        return R.layout.activity_setting;
//    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_setting;
    }

    @Override
    protected void initData(Bundle bundle) {
        setTtle("设置");
        if (!TextUtils.isEmpty(AppUtils.getAppVersionName())) {
            tvVersionCode.setText(AppUtils.getAppVersionName());
        }
    }

    @Override
    protected IPresenter onLoadPresenter() {
        return null;
    }



    @OnClick({R.id.rl_cache, R.id.ct_logOut})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_cache:

                LoadingDialog dialog = new LoadingDialog(this);
                dialog.setContent("清除中");
                dialog.show();
                if (CacheUtils.getInstance().clear()) {

                    ToastUtils.showShortSafe("缓存清除成功");
                    if (dialog != null && dialog.isShowing()) {
                        dialog.dismiss();
                    }
                } else {
                    ToastUtils.showShortSafe("缓存清除失败");
                    if (dialog != null && dialog.isShowing()) {
                        dialog.dismiss();
                    }
                }
                break;
            case R.id.ct_logOut:

                CommonTowBtnDialog towBtnDialog = new CommonTowBtnDialog(mContext);
//
                towBtnDialog.setContent("您确定要退出当前账号登录么?")
                        .setLeft("确定")
                        .setRight("取消")
                        .setDialogButtonOnClickListener(new CommonTowBtnDialog.DialogButtonOnClickListener() {
                            @Override
                            public void onLeft(View v) {
                                SPUtils.getInstance().remove(SPConstants.KEY_USER_TOKEN);
                                AppManager.getAppManager().finishActivity(WebActivity.class);
                                //停止极光
                                JPushUitil.getInstance().removePush();
                                gotoActivity(LoginActivity.class);
                            }

                            @Override
                            public void onRight(View v) {
                            }
                        })
                        .show();
                break;
        }
    }
}
